<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>忘记密码</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${request.contextPath}/static/libs/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${request.contextPath}/static/modules/web/kdayunadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="${request.contextPath}/static/modules/web/kdayunadmin/style/login.css" media="all">
    <@config id=Global.SYSOPTKEY_ISOPENZHIHUI orgid="${orgid}">
        <link id="filterCss" rel="stylesheet"
            href="${request.contextPath}/static/modules/manager/css/filter.css?v=<@configVersion suosxt='CORE'> </@configVersion>"
            media="all">
    </@config>
    <link rel="icon" href="${request.contextPath}<@configValue id='CAAB580980C74A169D8AFEB418ABB5AA'> </@configValue>"
        type="image/x-icon" />
</head>
<style>
    .strenth-bar {
        display: inline-block;
        border: 1px solid #ccc;
        padding: 2px 5px;
        border-radius: 8px;
        vertical-align: sub;
    }

    .strenth-bar .layui-progress {
        width: 150px;
        height: 8px;
        float: left;
        border-radius: 0;
    }

    .strenth-bar .layui-progress .layui-progress-bar {
        width: 0;
        height: 8px;
        border-radius: 0;
    }
</style>

<body id="zhengling-zhuye">
    <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
        <div class="layadmin-user-login-main">
            <div class="layadmin-user-login-box layadmin-user-login-header">
                <h2>忘记密码</h2>
                <p>
                    <@configValue orgid='${orgid}' id=Global.SYSOPTKEY_SYSNAME> </@configValue>
                </p>
            </div>
            <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
                <div class="layui-form-item">
                    <input type="hidden" value="${vcodekey}" name="vcodekey">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-cellphone"
                        for="LAY-user-login-cellphone"></label>
                    <input type="text" name="cellphone" id="LAY-user-login-cellphone" lay-verify="required|phone"
                        placeholder="请输入手机号" class="layui-input" maxlength="11">
                </div>
                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="PSW"></label>
                    <input type="password" name="PSW" id="LAY-user-login-password" lay-verify="required|pass"
                        placeholder="请输入新密码" class="layui-input" maxlength="16" autocomplete="off">
                    <@configNot id=Global.SYSOPTKEY_ISOPENPASSWORDINFO value='none' orgid='${orgid}'>
                        <div style="padding-top: 2px; padding-left:12px">
                            <span class="psStrong" style="wdith:15px;height:15px">密码强度</span>
                            <div class="strenth-bar">
                                <div class="layui-progress" lay-filter="strenth">
                                    <div class="layui-progress-bar"></div>
                                </div>
                            </div>
                            <span class="strenth_Text">无</span>
                        </div>
                    </@configNot>

                <div class="layui-form-item">
                    <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="repass"></label>
                    <input type="password" name="repass" id="LAY-user-login-repass" lay-verify="required|pass"
                        placeholder="确认新密码" class="layui-input" maxlength="16" autocomplete="off">
                </div>
                <div class="layui-form-item">
                    <div class="layui-row">
                        <div class="layui-col-xs7">
                            <label class="layadmin-user-login-icon layui-icon layui-icon-vercode"
                                for="LAY-user-login-vercode"></label>
                            <input type="text" name="vercode" id="LAY-user-login-vercode" lay-verify="required"
                                placeholder="图形验证码" class="layui-input">
                        </div>
                        <div class="layui-col-xs5">
                            <div style="margin-left: 10px;">
                                <img id="captchaImg" class="layadmin-user-login-codeimg" id="LAY-user-get-vercode">
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-row">
                        <div class="layui-col-xs7">
                            <label class="layadmin-user-login-icon layui-icon layui-icon-vercode"
                                for="LAY-user-login-smscode"></label>
                            <input type="text" name="phonecode" id="LAY-user-login-smscode" lay-verify="required"
                                placeholder="短信验证码" class="layui-input">
                        </div>
                        <div class="layui-col-xs5">
                            <div style="margin-left: 10px;">
                                <button type="button" class="layui-btn layui-btn-primary layui-btn-fluid"
                                    id="LAY-user-getsmscode">获取验证码</button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn layui-btn-fluid" id="submit" lay-submit
                        lay-filter="LAY-user-forget-submit">提交</button>
                </div>
                <div class="layui-trans layui-form-item layadmin-user-login-other" style="padding-top:0">
                    <a href="${request.contextPath}/logout"
                        class="layadmin-user-jump-change layadmin-link layui-show-xs-inline-block layui-hide-xs">返回登录界面</a>
                </div>
            </div>
        </div>

        <div class="layui-trans layadmin-user-login-footer">
            <#include "/web/foot.ftl" />
        </div>

    </div>

    <script src="${request.contextPath}/static/libs/layui/layui.js"></script>
    <script type="text/javascript" src="${request.contextPath}/static/libs/md5.js" type="text/javascript"></script>
    <script>
        layui.config({
            version: "<@configVersion suosxt='CORE'> </@configVersion>"
            , base: '${request.contextPath}/static/framework/' //静态资源所在路径
            , contentPath: '${request.contextPath}'
        }).use(['zlConfig', 'zlContext', 'layer', 'form', 'element'], function () {
            var $ = layui.$
                , zlContext = layui.zlContext
                , layer = layui.layer
                , zlConfig = layui.zlConfig
                , statusName = zlConfig.global.result.statusName
                , msgName = zlConfig.global.result.msgName
                , dataName = zlConfig.global.result.dataName
                , ERROR = zlConfig.global.result.errorState
                , OK = zlConfig.global.result.okState
                , form = layui.form
                , element = layui.element;

            function reloadVcode() {
                var vcodekey = $('input[name="vcodekey"]').val();
                var url = "${request.contextPath}/captcha.jpg?vcodekey=" + vcodekey + "&type=simple&t=" + Math.floor(Math.random() * 100);
                $("#captchaImg").prop("src", url);
            }
            $("#captchaImg").click(function () {
                reloadVcode();
            });
            reloadVcode();

            function getSmsCode() {
                var phone = $("#LAY-user-login-cellphone").val();
                if (!zlContext.verifyPhone(phone, "请输入正确的手机号")) {
                    $("#LAY-user-login-cellphone").focus();
                    return false;
                }
                var vcode = $("#LAY-user-login-vercode").val();
                if (!vcode) {
                    layer.msg("请输入图形校验码");
                    $("#LAY-user-login-vercode").focus();
                    return false;
                }
                var psw = $('input[name="PSW"]').val();
                var repsw = $('input[name="repass"]').val();
                if (psw != repsw) {
                    layer.msg("两次输入密码不一致，请重新输入！");
                    $('input[name="repass"]').focus();
                    return false;
                }

                //校验手机号是否存在
                var count = 0;
                zlContext.asyncGet(layui.cache['contentPath'] + "/core/sms/phone/hasexisted", { 'phone': phone }, function (result) {
                    if (OK == result[statusName]) {
                        if (result[dataName]) {
                            count = result[dataName].hasExisted;
                        }
                    }
                }, true)
                //手机未注册
                if (count == 0) {
                    layer.msg("该手机号未注册！");
                    return false;
                }
                if (count > 1) {
                    layer.msg("该手机号重复注册！");
                    return false;
                }

                var vcodekey = $('input[name="vcodekey"]').val();
                var param = {
                    'phone': phone,
                    'vcode': vcode,
                    'vcodekey': vcodekey,
                    'orgid': "${orgid}"
                }
                zlContext.get(layui.cache['contentPath'] + "/core/sms/send/forgetpwd/smscode", param, function (result) {
                    if (OK == result[statusName]) {
                        zlContext.successMsg(result[msgName]);
                        zlContext.setCountdown(60, 'LAY-user-getsmscode', true);
                    } else {
                        reloadVcode();
                        zlContext.errorMsg(result[msgName]);
                    }
                }, true);
            }

            $("#LAY-user-getsmscode").click(function () {
                getSmsCode();
            });
            function checkPassWord(value) {
                // 0： 表示第一个级别 弱 1：表示第二个级别 中 2：表示第三个级别 强
                // 3： 表示第四个级别 4：表示第五个级别
                var modes = 0;
                if (value.length < 6) {//最初级别
                    return modes;
                }
                if (/\d/.test(value)) {//如果用户输入的密码 包含了数字
                    modes++;
                }
                if (/[a-z]/.test(value)) {//如果用户输入的密码 包含了小写的a到z
                    modes++;
                }
                if (/[A-Z]/.test(value)) {//如果用户输入的密码 包含了大写的A到Z
                    modes++;
                }
                if (/\W/.test(value)) {//如果是非数字 字母 下划线
                    modes++;
                }
                return modes;
            };

            // 密码输入时 实时检测强度
            $('input[name="PSW"]').on('keyup', function () {
                var newLevel = checkPassWord($(this).val());
                if ($(this).val() == '') {
                    element.progress('strenth', '0');
                    $('span.strenth_Text').html('无').css('color', '#666');
                    return;
                }

                function progress(barColor, length, strenthText, textColor) {
                    $('div.layui-progress-bar').removeClass(function (index, classname) {
                        return classname.substr(19)
                    }).addClass('layui-bg-' + barColor)
                    element.progress('strenth', length);
                    $('span.strenth_Text').html(strenthText).css('color', textColor);
                }

                switch (newLevel) {
                    case 0:
                        progress('red', '20%', '弱', '#FF5722')
                        break;
                    case 1:
                        progress('orange', '40%', '中', '#FFB800')
                        break;
                    case 2:
                        progress('blue', '60%', '强', '#1E9FFF')
                        break;
                    case 3:
                        progress('green', '80%', '很强', '#277FD0')
                        break;
                    case 4:
                        progress('cyan', '100%', '最强', '#2F4056')
                        break;
                }
            });

            form.on('submit(LAY-user-forget-submit)', function (data) {
                var psw = $('input[name="PSW"]').val();
                var repsw = $('input[name="repass"]').val();
                if (psw != repsw) {
                    layer.msg("两次输入密码不一致，请重新输入！");
                    $('input[name="repass"]').focus();
                    return false;
                }
                data.field.PSW = md5(data.field.PSW).toUpperCase();
                data.field.repass = md5(data.field.repass).toUpperCase();
                data.field.orgid = '${orgid}';
                zlContext.post(layui.cache['contentPath'] + "/admin/coreuser/forgetpsw", data.field, function (result) {
                    if (OK == result[statusName]) {
                        zlContext.successAlert('重设密码成功，请返回登录页面！', function () {
                            top.location.href = layui.cache['contentPath'] + '/logout';
                            return true;
                        });
                    } else {
                        zlContext.errorMsg(result[msgName]);
                        reloadVcode();
                    }
                }, true);

            });
        });
    </script>
</body>

</html>